<?php
apf_require_class('Dao_DAO');
class Dao_hr_City extends DAO{
    public function get_table_name(){
        return 'city';
    }

    public function get_read_pdo_name(){
        return 'hroa_slave';
    }

    public function get_write_pdo_name(){
        return 'hroa_master';
    }

    public function get_table_pk(){
        return 'city_id';
    }

    public function build_data($cities) {
        $s_sql = 'SELECT c.department_id,b.relation_id,b.user_id,a.user_name,a.job_status,b.parent_id,b.user_job_id,c.department_id,d.department_name,e.bu_name,d.city_id FROM user AS a
                LEFT JOIN relation AS b ON a.user_id = b.user_id
                LEFT JOIN job AS c ON b.user_job_id = c.job_id
                LEFT JOIN department AS d ON c.department_id = d.department_id
                LEFT JOIN business_unit AS e ON d.bu_id = e.bu_id';

        $rs = $this->execute($s_sql, array(),"hroa_slave");
        if(empty($rs)) {return array();}

        $arr = array();
        foreach($rs as $v) {
            if($v['job_status'] != '1' || empty($v['department_id']) || empty($v['user_id']) || empty($v['user_job_id'])) {continue;}
            $arr[$v['relation_id']]['user_id'] = $v['user_id'];
            $arr[$v['relation_id']]['user_name'] = $v['user_name'];
            $arr[$v['relation_id']]['parent_id'] = $v['parent_id'];
            $arr[$v['relation_id']]['user_job_id'] = $v['user_job_id'];
            $arr[$v['relation_id']]['department_name'] = $v['department_name'];
            $arr[$v['relation_id']]['bu_name'] = $v['bu_name'];
            $arr[$v['relation_id']]['city_name'] = $cities[$v['city_id']];
            $arr[$v['relation_id']]['department_id'] = $v['department_id'];
        }

        return $arr;
    }
}
